//
//  ServiceContentTabVC.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/10/29.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "ServiceContentTabVC.h"
#import "ServiceContentHeadCell.h"
#import "HomeServiceDetailsIntroductionContentOneCell.h"
#import "HomeServiceDetailsIntroductionContentTwoCell.h"
#import "ShopCell.h"
#import "WriteRequirementTitleCell.h"
#import "EvaluationCell.h"
#import "ServiceEvaluationCell.h"
#import "EvaluationMoreCell.h"
#import "ServiceEvaluationModel.h"
#import "ImageViewCell.h"
#import "ServiceCell.h"
#import "CellFrameModel.h"
#import "ServiceModel.h"
#import "ShopModel.h"
#import "ShopSubModel.h"
#import "ServiceEvaluationModel.h"
#import "EvaluationView.h"
#import "UIImage+ImgSize.h"
#import "MyCollectShopContentVC.h"
#import "ShopEvaluationModel.h"
#import "ShopEvaluationAssociationModel.h"
#import "ShopEvaluationEvaluateInfosModel.h"
#import "XHWebImageAutoSize.h"
#import "ContentCell.h"
#import "ArrowheadMenu.h"// 箭头菜单
#import "YHPhotoBrowser.h"
#import "ReleaseServiceTabVC.h"
#import "CustomeEvaluate.h"
@interface ServiceContentTabVC ()<UITableViewDelegate,UITableViewDataSource,EvaluationCellDelegate,ServiceEvaluationCellDelegate,EvaluationMoreCellDelegate,ShopCellDelegate,ServiceContentHeadCellDelegate,MenuViewControllerDelegate>
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) UIView *sectionHeadView;
@property(nonatomic,strong) EvaluationView *evaluationView;
@property(nonatomic,strong) NSMutableArray *dataMuta;
@property(nonatomic,strong) NSMutableArray *shopArray;
@property(nonatomic,strong) NSMutableArray *serviceEvaluationArray;
@property(nonatomic,strong) NSMutableArray *serviceRecommandArray;
@property(nonatomic,strong) NSString *urlString;
@property(nonatomic,strong) NSDictionary *dict;
@property(nonatomic,strong) AFHTTPSessionManager *manager;
@property(nonatomic,assign) NSInteger page;
@property(nonatomic,assign) NSInteger rows;
@property(nonatomic,assign) NSInteger aid;
@property(nonatomic,assign) NSInteger pages;
@property(nonatomic,assign) NSInteger type;
@property(nonatomic,assign) NSInteger *uid;
@property(nonatomic,strong) NSIndexPath *reloadIndexPath;
@property(nonatomic,strong) NSMutableArray *images;
@property(nonatomic,assign) NSInteger goodsCount;
@property(nonatomic,assign) NSInteger mediumsCount;
@property(nonatomic,assign) NSInteger terriblesCount;
@property(nonatomic,strong) UIButton *contactBtn;
@property(nonatomic,strong) NSMutableArray *shopEvaluationMuta;
@property(nonatomic,strong) NSMutableArray *shopEvaluationAssociationMuta;
@property(nonatomic,strong) NSMutableArray *shopEvaluationEvaluateInfosMuta;
//@property(nonatomic,strong) UIButton *collectBtn;
@property(nonatomic,assign) BOOL collectService;
@property(nonatomic,assign) NSInteger collectShop;
@property(nonatomic,assign) NSInteger index;
@property(nonatomic,assign) NSInteger headHeight;
@property(nonatomic,strong) NSMutableArray *complainMuta;
@property(nonatomic,assign) NSInteger complationIndex;
@property(nonatomic,strong) ShopEvaluationEvaluateInfosModel *complainModel;
@property(nonatomic,assign) NSInteger tag;
@end
static NSString *identifierWriteRequirementTitleCell = @"WriteRequirementTitleCell";
static NSString *identifierHomeServiceDetailsIntroductionContentTwoCell = @"HomeServiceDetailsIntroductionContentTwoCell";
static NSString *identifier = @"ServiceContentHeadCell";
static NSString *identifierOne = @"HomeServiceDetailsIntroductionContentOneCell";
static NSString *identifierTwo = @"HomeServiceDetailsIntroductionContentTwoCell";
static NSString *identifierShop = @"ShopCell";
static NSString *identifierImageViewCell = @"ImageViewCell";
static NSString *identifierServiceCell = @"ServiceCell";
static NSString *identifierCell = @"cell";
static NSString *identifierEvaluationCell = @"evaluationCell";
static NSString *identifierServiceEvaluationCell = @"serviceEvaluationCell";
static NSString *identifierServiceEvaluationMore = @"moreCell";
static NSString *identifierContent = @"contentCell";
@implementation ServiceContentTabVC
-(NSMutableArray *)complainMuta
{
    if (!_complainMuta) {
        NSArray *pathFile = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *complain = @"";
        NSArray *temp = nil;
        complain = [pathFile[0] stringByAppendingPathComponent:@"complainMuta.plist"];
        temp = [NSArray arrayWithContentsOfFile:complain];
        if (temp.count) {
            _complainMuta = [NSMutableArray arrayWithArray:temp];
        }else {
            _complainMuta = [NSMutableArray array];
        }
        
    }
    return _complainMuta;
    
}
-(NSMutableArray *)dataMuta
{
    if (!_dataMuta) {
        _dataMuta = [NSMutableArray array];
    }
    return _dataMuta;
}
-(NSMutableArray *)shopEvaluationMuta
{
    if (!_shopEvaluationMuta) {
        _shopEvaluationMuta = [NSMutableArray array];
    }
    return _shopEvaluationMuta;
}
-(NSMutableArray *)shopEvaluationAssociationMuta
{
    if (!_shopEvaluationAssociationMuta) {
        _shopEvaluationAssociationMuta = [NSMutableArray array];
    }
    return _shopEvaluationAssociationMuta;
}
-(NSMutableArray *)shopEvaluationEvaluateInfosMuta
{
    if (!_shopEvaluationEvaluateInfosMuta) {
        _shopEvaluationEvaluateInfosMuta = [NSMutableArray array];
    }
    return _shopEvaluationEvaluateInfosMuta;
}
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kVWidth, kVHeight-kNavAndStatusHight)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
-(NSMutableArray *)shopArray
{
    if (!_shopArray) {
        _shopArray = [NSMutableArray array];
    }
    return _shopArray;
}
-(NSMutableArray *)serviceRecommandArray
{
    if (!_serviceRecommandArray) {
        _serviceRecommandArray = [NSMutableArray array];
    }
    return _serviceRecommandArray;
}
-(NSMutableArray *)images
{
    if (!_images) {
        _images = [NSMutableArray array];
    }
    return _images;
}
-(NSMutableArray *)serviceEvaluationArray
{
    if (!_serviceEvaluationArray) {
        _serviceEvaluationArray = [NSMutableArray array];
    }
    return _serviceEvaluationArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"服务详情";
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.complainModel = [[ShopEvaluationEvaluateInfosModel alloc]init];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"icon_111"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(clickRightItem:)];
    self.manager = [AFHTTPSessionManager manager];
    self.images = [NSMutableArray arrayWithArray:[self.model.images componentsSeparatedByString:@","]];
    [self.view addSubview:self.tableView];
    XLog(@"self.model:%@",self.model);
    [self.tableView registerNib:[UINib nibWithNibName:@"WriteRequirementTitleCell" bundle:nil] forCellReuseIdentifier:identifierWriteRequirementTitleCell];
    [self.tableView registerClass:[HomeServiceDetailsIntroductionContentTwoCell class] forCellReuseIdentifier:identifierHomeServiceDetailsIntroductionContentTwoCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"ServiceContentHeadCell" bundle:nil] forCellReuseIdentifier:identifier];
     [self.tableView registerNib:[UINib nibWithNibName:@"HomeServiceDetailsIntroductionContentOneCell" bundle:nil] forCellReuseIdentifier:identifierOne];
    [self.tableView registerClass:[HomeServiceDetailsIntroductionContentTwoCell class] forCellReuseIdentifier:identifierTwo];
    [self.tableView registerNib:[UINib nibWithNibName:@"ShopCell" bundle:nil] forCellReuseIdentifier:identifierShop];
    [self.tableView registerNib:[UINib nibWithNibName:@"ImageViewCell" bundle:nil] forCellReuseIdentifier:identifierImageViewCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"ServiceCell" bundle:nil] forCellReuseIdentifier:identifierServiceCell];
    [self.tableView registerClass:[ContentCell class] forCellReuseIdentifier:identifierContent];
    [self.tableView registerClass:[EvaluationCell class] forCellReuseIdentifier:identifierEvaluationCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"ServiceEvaluationCell" bundle:nil] forCellReuseIdentifier:identifierServiceEvaluationCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"EvaluationMoreCell" bundle:nil] forCellReuseIdentifier:identifierServiceEvaluationMore];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(listByIds:) name:@"listByIds" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkTokenServiceContent:) name:@"checkTokenServiceContent" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkTokenError:) name:@"checkTokenError" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkTokenServiceContentCallPhone:) name:@"checkTokenServiceContentCallPhone" object:nil];
    self.page = 1;
    self.rows = 5;
    self.type = 0;
    [self reloadInternetData];
    self.sectionHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kVWidth, 40)];
    [self.view addSubview:self.sectionHeadView];
    self.sectionHeadView.hidden = YES;
    self.sectionHeadView.backgroundColor = [UIColor whiteColor];
    for (int i = 0; i < 3; i++) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(kVWidth/3*i, 0, kVWidth/3, 40)];
        [self.sectionHeadView addSubview:btn];
        [btn addTarget: self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = i+1;
        NSArray *titles = @[@"详情介绍",@"客户评价",@"推荐"];
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        if (i == 0) {
            [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:16];
        }else {
            [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
        }
    }
    self.index = 0;
    self.contactBtn = [[UIButton alloc]initWithFrame:CGRectMake(kUIScreen.size.width*0.05, kUIScreen.size.height*0.8, kUIScreen.size.width*0.9, 44)];
    [self.view addSubview:self.contactBtn];
    [self.contactBtn setBackgroundColor:kOrangeBg];
    self.contactBtn.layer.masksToBounds = YES;
    self.contactBtn.layer.cornerRadius = 8;
    self.contactBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.contactBtn addTarget: self action:@selector(callBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.contactBtn setTitle:@"立即联系" forState:UIControlStateNormal];
}
#pragma mark-内容投诉
-(void)clickRightItem:(UIBarButtonItem *)sender
{
    self.complationIndex = 0;
    NSArray *pathFile = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *complain = @"";
    complain = [pathFile[0] stringByAppendingPathComponent:@"complainMuta.plist"];
    NSString *message = @"";
    if (self.complainMuta.count) {
        if (![self.complainMuta containsObject:[NumberSwitchString numberSwitchString:self.model.id]]) {
            message = @"投诉";
        }else {
            message = @"已投诉";
        }
    }else {
        message = @"投诉";
    }
    
    ArrowheadMenu *VC = [[ArrowheadMenu alloc] initDefaultArrowheadMenuWithTitle:@[message,@"新建服务"] icon:@[@"tousu",@"new_tianjia"] menuPlacements:ShowAtBottom ];
    VC.delegate = self;
    [VC presentMenuView:sender];
    XLog(@"NSHomeDirectory():%@",NSHomeDirectory());
}
// 菜单代理方法
- (void)menu:(BaseMenuViewController *)menu didClickedItemUnitWithTag:(NSInteger)tag andItemUnitTitle:(NSString *)title
{
    [menu dismissViewControllerAnimated:NO completion:^{
        if ([[UserDefaultsHelper readAutoLogIn] isEqualToString:@"NO"]) {
            [LogOutAccount presentOutAccount];
            [UIAlertViewWarningAccount showWarningAccount];
        }else if ([UserDefaultsHelper readAutoLogIn].length == 0) {
            [LogOutAccount presentOutAccount];
        }else {
            self.tag = tag;
            self.dict = @{
                          @"userId":[UserDefaultsHelper readUid],
                          @"token":[UserDefaultsHelper readToken]
                          };
            self.urlString = [NSString stringWithFormat:@"%@/user/checkToken",kUrl];
            [CustomeManager POSTCheckTokenWithURLIndex:5 parameters:self.dict success:^(NSDictionary *dict) {
                
            } failure:^(NSError *error) {
                
            }];
        }
    }];
}
#pragma mark-代理:checkToken
-(void)checkTokenServiceContent:(NSNotification *)info
{
    if (self.tag == 0) {
        NSArray *pathFile = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *complain = @"";
        complain = [pathFile[0] stringByAppendingPathComponent:@"complainMuta.plist"];
        NSArray *temp = [NSArray array];
        temp = [NSArray arrayWithContentsOfFile:complain];
        if (temp.count) {
            self.complainMuta = [NSMutableArray arrayWithArray:temp];
        }else {
            self.complainMuta = [NSMutableArray array];
        }
        if (self.complainMuta.count) {
            if (![self.complainMuta containsObject:[NumberSwitchString numberSwitchString:self.model.id]]) {
                [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"投诉成功"];
                [self.complainMuta addObject:[NumberSwitchString numberSwitchString:self.model.id]];
                [self.complainMuta writeToFile:complain atomically:YES];
            }else {
                [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"不可重复投诉"];
            }
        }else {
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"投诉成功"];
            [self.complainMuta addObject:[NumberSwitchString numberSwitchString:self.model.id]];
            [self.complainMuta writeToFile:complain atomically:YES];
        }
    }else {
        ReleaseServiceTabVC *vc = [[ReleaseServiceTabVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}
#pragma mark-代理:收藏
- (void)serviceContentHeadCell:(id)serviceContentHeadCell withCollectBtn:(UIButton *)collectBtn withIndexPath:(nonnull NSIndexPath *)indexPath
{
    if ([[UserDefaultsHelper readAutoLogIn] isEqualToString:@"NO"]) {
        [LogOutAccount presentOutAccount];
        [UIAlertViewWarningAccount showWarningAccount];
    }else if ([UserDefaultsHelper readAutoLogIn].length == 0) {
        [LogOutAccount presentOutAccount];
    }else {
        self.dict = @{
                      @"userId":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken]
                      };
        self.urlString = [NSString stringWithFormat:@"%@/user/checkToken",kUrl];
        [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSInteger status = [[responseObject objectForKey:@"status"] integerValue];
            if (status == 200) {
                collectBtn.selected = !collectBtn.selected;
                XLog(@"collectBtn.selected:%d",collectBtn.selected);
                self.urlString = [NSString stringWithFormat:@"%@/collection/insertCollection",kUrl];
                self.dict = @{
                              @"uid":[UserDefaultsHelper readUid],
                              @"token":[UserDefaultsHelper readToken],
                              @"type":@"2",
                              @"status":[NumberSwitchString numberSwitchString:collectBtn.selected],
                              @"id":[NumberSwitchString numberSwitchString:self.model.id]
                              };
                XLog(@"self.dict:%@",self.dict);
                [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    XLog(@"responseObject:%@",responseObject);
                    NSString *message = [responseObject objectForKey:@"message"];
                    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        if (self.returnValueBlock) {
                            self.returnValueBlock(0);
                        };
                    });
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    XLog(@"error:%@",error);
                }];
            }else {
                [UIAlertViewWarningAccount showWarningAccount];
                [LogOutAccount presentOutAccount];
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
    }
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
#pragma mark-查询店铺信息,评价
-(void)reloadInternetData
{
    [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
    [WSProgressHUD show];
    //使用GCD的信号量 dispatch_semaphore_t 创建同步请求
    dispatch_group_t group =dispatch_group_create();
    dispatch_queue_t globalQueue=dispatch_get_global_queue(0, 0);
    dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
    dispatch_group_async(group, globalQueue, ^{
        for (int i = 0; i<4; i++) {
            if (i == 0) {
                self.urlString = [NSString stringWithFormat:@"%@/association/searchContent",kUrl];
                self.dict = @{//服务详情
                              @"id":[NumberSwitchString numberSwitchString:self.model.id],
                              @"uid":[UserDefaultsHelper readUid],
                              @"token":[UserDefaultsHelper readToken]
                              };
            }else if (i == 1) {//查询店铺
//                self.urlString = [NSString stringWithFormat:@"%@/shop/selectShopByUid",kUrl];
                self.urlString = [NSString stringWithFormat:@"%@/shop/selectShopByUid",kUrl];
                NSString *uidS = [NSString stringWithFormat:@"%ld",(long)self.model.uid];
                self.dict = @{
                              @"suid":uidS
                              };
            }else if (i == 2) {//获取评价列表
                NSString *types = [NSString stringWithFormat:@"%ld",(long)self.type];
                NSString *pageS = [NSString stringWithFormat:@"%ld",(long)self.page];
                NSString *aidS = [NSString stringWithFormat:@"%ld",(long)self.model.id];
                NSString *rowS = [NSString stringWithFormat:@"%ld",(long)self.rows];
                self.urlString = [NSString stringWithFormat:@"%@/associationEvaluate/list",kUrl];
                self.dict = @{
                              @"aid":aidS,
                              @"page":pageS,
                              @"rows":rowS,
                              @"type":types,
                              @"uid":[UserDefaultsHelper readUid]
                              };
            }else {//推荐
                self.urlString = [NSString stringWithFormat:@"%@/association/search",kUrl];
                self.dict = @{
                              @"uid":@"",
                              @"associationtype":@"",
                              @"associationtypesub1":@"",
                              @"associationtypesub2":@"",
                              @"commonindustry":@"",
                              @"industry":self.model.industry,
                              @"type":@"",
                              @"order":@"",
                              @"page":@"1",
                              @"rows":@"5",
                              @"address":@""
                              };

            }
            [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                if (i == 0) {
                    XLog(@"ServiceContentTabVC:%@",responseObject);
                    XLog(@"i:%d",i);
                    XLog(@"self.dict:%@",self.dict);
                    XLog(@"urlString:%@",self.urlString);
                    XLog(@"HomeresponseObjectHeader:%@",responseObject);
                    NSInteger status = [[responseObject objectForKey:@"status"]integerValue];
                    if (status == 203) {
                        [LogOutAccount presentOutAccount];
                        [UIAlertViewWarningAccount showWarningAccount];
                    }
                    NSDictionary *date = [responseObject objectForKey:@"date"];
                    XLog(@"date:%@",date);
                    ServiceModel *model = [ServiceModel mj_objectWithKeyValues:date];
                    [self.dataMuta addObject:model];
                }else if (i == 1) {
                    XLog(@"HomeresponseObject1:%@",responseObject);
                    NSDictionary *date = [responseObject objectForKey:@"date"];
                    if(date != nil){
                        ShopSubModel *ShopSubModell = [ShopSubModel mj_objectWithKeyValues:date];
                        [self.shopArray addObject:ShopSubModell];
                    }
                }else if (i == 2) {
                    XLog(@"HomeresponseObject2:%@",responseObject);
                    NSDictionary *date = [responseObject objectForKey:@"date"];
                    self.goodsCount = [[date objectForKey:@"goodsCount"] integerValue];
                    self.mediumsCount = [[date objectForKey:@"mediumsCount"] integerValue];
                    self.terriblesCount = [[date objectForKey:@"terriblesCount"] integerValue];
                    ShopEvaluationModel *shopEvaluationModel = [ShopEvaluationModel mj_objectWithKeyValues:date];
                    [self.shopEvaluationMuta addObject:shopEvaluationModel];
                    NSArray *evaluateInfos =  [date objectForKey:@"evaluateInfos"];
                    //                    XLog(@"evaluateInfos.count:%ld",evaluateInfos.count);
                    if (evaluateInfos.count) {
                        for (NSDictionary *dict in evaluateInfos) {
                            //                            XLog(@"dict:%@",dict);
                            ShopEvaluationEvaluateInfosModel *shopEvaluationEvaluateInfosModel = [ShopEvaluationEvaluateInfosModel mj_objectWithKeyValues:dict];
                            [self.shopEvaluationEvaluateInfosMuta addObject:shopEvaluationEvaluateInfosModel];
                            NSDictionary *association = [dict objectForKey:@"association"];
                            ShopEvaluationAssociationModel *shopEvaluationModel = [ShopEvaluationAssociationModel mj_objectWithKeyValues:association];
                            [self.shopEvaluationAssociationMuta addObject:shopEvaluationModel];
                        }
                    }
                }else {
                    NSArray *date = [responseObject objectForKey:@"date"];
                    if (date.count) {
                        for (NSDictionary *dict in date) {
                            ServiceModel *model = [ServiceModel mj_objectWithKeyValues:dict];
                            [self.serviceRecommandArray addObject:model];
                        }
                    }
                }
                dispatch_semaphore_signal(semaphore);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                XLog(@"error:%@",error);
                dispatch_semaphore_signal(semaphore);
            }];
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        }

    });

    dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{
        XLog(@"%@---全部结束。。。",[NSThread currentThread]);
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
            if (!self.dataMuta.count) {
                 [WSProgressHUD showImage:[UIImage imageNamed:@""] status:[NSBundle bundleLocalizedStringForKey:@"footerNoInternet"]];
            }else {
                [WSProgressHUD dismiss];
            }
        });
    });
}
-(void)clickBtn:(UIButton *)clickBtn
{
    if (clickBtn.tag == 1) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }else if (clickBtn.tag == 2) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:6];
        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }else {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:7];
        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{

    NSArray *visible       = [self.tableView indexPathsForVisibleRows];
    NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:0];
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:6 inSection:1];
    HomeServiceDetailsIntroductionContentTwoCell *cell1 = [self.tableView cellForRowAtIndexPath:indexPath1];
    CGFloat scrollY1 = CGRectGetMaxY(cell1.frame)-60;
    NSIndexPath *indexPath2 = [NSIndexPath indexPathForRow:0 inSection:5];
     ShopCell *cell2 = [self.tableView cellForRowAtIndexPath:indexPath2];
    CGFloat scrollY2 = CGRectGetMaxY(cell2.frame)-60;
    NSIndexPath *indexPath3 = [NSIndexPath indexPathForRow:0 inSection:7];
    WriteRequirementTitleCell *cell3 = [self.tableView cellForRowAtIndexPath:indexPath3];
    CGFloat scrollY3 = CGRectGetMinY(cell3.frame)-60;
//    XLog(@"index:%ld---%ld",(long)indexpath.row,(long)indexpath.section);
    XLog(@"scrollY1:%f",scrollY1);
    XLog(@"scrollY2:%f",scrollY2);
    XLog(@"scrollY3:%f",scrollY3);
    if ((scrollView.contentOffset.y>=scrollY1&&scrollY1>0) ||scrollY1== -60) {
        self.index = 1;
    }else {
        self.index = 0;
    }
    if (scrollView.contentOffset.y<=self.headHeight) {
        self.index = 0;
    }
    if ((scrollView.contentOffset.y>=scrollY2&&scrollY2>0)||indexpath.section == 6) {
        self.index = 2;
    }
    if ((scrollView.contentOffset.y>=scrollY3&&scrollY3>0) ||indexpath.section == 7) {
        self.index = 3;
    }
    XLog(@"self.index:%ld",self.index);
    if (self.index == 0) {
        self.sectionHeadView.hidden = YES;
        self.contactBtn.hidden = NO;
        for (id obj in self.sectionHeadView.subviews) {
            if ([obj isKindOfClass:[UIButton class]]) {
                UIButton *btn = (UIButton *)obj;
                if (btn.tag == 1) {
                    [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:16];
                }else{
                    [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:14];
                }
            }
        }
    }
    if (self.index == 1) {
        self.sectionHeadView.hidden = NO;
        self.contactBtn.hidden = NO;
        for (id obj in self.sectionHeadView.subviews) {
            if ([obj isKindOfClass:[UIButton class]]) {
                UIButton *btn = (UIButton *)obj;
                if (btn.tag == 1) {
                    [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:16];
                }else{
                    [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:14];
                }
            }
        }
    }else  if (self.index == 2) {
        self.sectionHeadView.hidden = NO;
        self.contactBtn.hidden = YES;
        for (id obj in self.sectionHeadView.subviews) {
            if ([obj isKindOfClass:[UIButton class]]) {
                UIButton *btn = (UIButton *)obj;
                if (btn.tag == 2) {
                    [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:16];
                }else{
                    [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:14];
                }
            }
        }
    }else if (self.index == 3) {
        self.sectionHeadView.hidden = NO;
        for (id obj in self.sectionHeadView.subviews) {
            if ([obj isKindOfClass:[UIButton class]]) {
                UIButton *btn = (UIButton *)obj;
                if (btn.tag == 3) {
                    [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:16];
                }else{
                    [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
                    btn.titleLabel.font = [UIFont systemFontOfSize:14];
                }
            }
        }
    }
    NSIndexPath *visiblePath = [[self.tableView indexPathsForVisibleRows] firstObject];
    XLog(@"visiblePath:%ld",visiblePath.section);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 8;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }else if (section == 1) {
        return 7;
    }else if (section == 2) {
        return 3;
    }else if (section == 3) {
        return 2;
    }else if (section == 4) {
        return self.images.count?self.images.count+1:2;
    }else if (section == 5) {
        return 1;
    }else if (section == 6) {
        return self.shopEvaluationEvaluateInfosMuta.count?self.shopEvaluationEvaluateInfosMuta.count+3:3;
    }else {
        return self.serviceRecommandArray.count?self.serviceRecommandArray.count+1:0;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
     if (indexPath.section == 0) {
         ServiceContentHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
         cell.delegate = self;
         cell.indexPath = indexPath;
         if (self.dataMuta.count) {
             ServiceModel *model = self.dataMuta[0];
             cell.serviceModel = model;
         }
         return cell;
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierWriteRequirementTitleCell forIndexPath:indexPath];
            cell.titleL.text = @"重要信息说明";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            HomeServiceDetailsIntroductionContentTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierHomeServiceDetailsIntroductionContentTwoCell forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.indexPath = indexPath;
//            cell.serviceModel = self.model;
            CellFrameModel *frameModel = [[CellFrameModel alloc]init];
            frameModel.indexPath = indexPath;
            frameModel.serviceModel = self.model;
            cell.frameTakeModel = frameModel;
            return cell;
        }
    }else if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierWriteRequirementTitleCell forIndexPath:indexPath];
            cell.titleL.text = @"业务详细介绍";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            HomeServiceDetailsIntroductionContentTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierHomeServiceDetailsIntroductionContentTwoCell forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.indexPath = indexPath;
            cell.serviceModel = self.model;
            CellFrameModel *frameModel = [[CellFrameModel alloc]init];
            frameModel.indexPath = indexPath;
            frameModel.serviceModel = self.model;
            cell.frameTakeModel = frameModel;
            return cell;
        }
    }else if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierWriteRequirementTitleCell forIndexPath:indexPath];
            cell.titleL.text = @"业务特色";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            ContentCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierContent forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.serviceModel = self.model;
            return cell;
        }
    }else if (indexPath.section == 4) {
        if (indexPath.row == 0) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierWriteRequirementTitleCell forIndexPath:indexPath];
            cell.titleL.text = @"图文介绍";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            ImageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierImageViewCell forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            NSString *url = self.images[indexPath.row -1];
            [cell.iv sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"noImage"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                /** 缓存image size */
                [XHWebImageAutoSize storeImageSize:image forURL:imageURL completed:^(BOOL result) {
                    /** reload  */
                    if(result)  [tableView  xh_reloadDataForURL:imageURL];
                }];
            }];
            cell.serviceModel = self.model;
            return cell;
        }
    }else if (indexPath.section == 5) {
        ShopCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierShop forIndexPath:indexPath];
        cell.delegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        ShopSubModel *shopSubModell = self.shopArray[0];
        cell.shopSubModell = shopSubModell;
        return cell;
    }else if (indexPath.section == 6) {
        if (indexPath.row == 0) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierWriteRequirementTitleCell forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.titleL.text = @"服务评价";
            return cell;
        }else if (indexPath.row == 1) {
            EvaluationCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierEvaluationCell forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.delegate = self;
            cell.goodsCount = self.goodsCount;
            cell.mediumsCount = self.mediumsCount;
            cell.terriblesCount = self.terriblesCount;
            return cell;
        }else {
            if (self.shopEvaluationEvaluateInfosMuta.count) {
                if (self.shopEvaluationEvaluateInfosMuta.count >= indexPath.row-1) {
                    ServiceEvaluationCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierServiceEvaluationCell forIndexPath:indexPath];
                    cell.indexPath = indexPath;
                    cell.delegate = self;
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    ShopEvaluationEvaluateInfosModel *shopEvaluationEvaluateInfosModel = self.shopEvaluationEvaluateInfosMuta[indexPath.row-2];
                    cell.shopEvaluationEvaluateInfosModel = shopEvaluationEvaluateInfosModel;
                    ShopEvaluationAssociationModel *shopEvaluationModel = self.shopEvaluationAssociationMuta[indexPath.row];
                    cell.shopEvaluationModel = shopEvaluationModel;
                    return cell;
                }else {
                    EvaluationMoreCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifierServiceEvaluationMore forIndexPath:indexPath];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.delegate = self;
                    
                    return cell;
                }
            }else {
                EvaluationMoreCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifierServiceEvaluationMore forIndexPath:indexPath];
                if (!self.shopEvaluationEvaluateInfosMuta.count){
                    [cell.moreBtn setTitle:@"没有更多内容了～" forState:UIControlStateNormal];
                    cell.moreBtn.userInteractionEnabled = NO;
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                return cell;
            }
        }
        
    }else {
        if (indexPath.row == 0) {
            WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierWriteRequirementTitleCell forIndexPath:indexPath];
            cell.titleL.text = @"相关业务推荐";
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        else  {
            ServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierServiceCell forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            ServiceModel *model = self.serviceRecommandArray[indexPath.row-1];
            cell.serviceModel = model;
            return cell;
        }
    }
   
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        return 210;
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            return 40;
        }else {
            CellFrameModel *frameModel = [[CellFrameModel alloc]init];
            frameModel.indexPath = indexPath;
            frameModel.serviceModel = self.model;
            return frameModel.cellHeight;
        }
    }else if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            return 40;
        }else {
            CellFrameModel *frameModel = [[CellFrameModel alloc]init];
            frameModel.indexPath = indexPath;
            frameModel.serviceModel = self.model;
            return frameModel.cellHeight;
        }
    }else if (indexPath.section == 3) {
        if (indexPath.row == 0) {
            return 60;
        }else {
            CGFloat cellHeight = [MCLabel getHeightByWidth:kVWidth-18*2 title:self.model.represent font:13]*1.4;
            XLog(@"cellHeight:%f",cellHeight);
            return cellHeight;
        }
    }else if (indexPath.section == 4) {
        if (indexPath.row == 0) {
            return 60;
        }
        else {
            if (self.model.images.length != 0) {
                XLog(@"imageHeightForURL:%f",[XHWebImageAutoSize imageHeightForURL:[NSURL URLWithString:self.images[indexPath.row -1]] layoutWidth:[UIScreen mainScreen].bounds.size.width estimateHeight:200]);
                return [XHWebImageAutoSize imageHeightForURL:[NSURL URLWithString:self.images[indexPath.row -1]] layoutWidth:[UIScreen mainScreen].bounds.size.width-36 estimateHeight:200];
            }else {
                return 100;
            }
        }
    }else if (indexPath.section == 5) {
        return 140;
    }else if (indexPath.section == 6) {
        if (indexPath.row == 0) {
            return 40;
        }else if (indexPath.row == 1) {
            return 60;
        }else if (self.shopEvaluationEvaluateInfosMuta.count >= indexPath.row-1) {
            ServiceEvaluationModel *serviceModel = self.shopEvaluationEvaluateInfosMuta[indexPath.row-2];
            CGFloat cellHeight = [MCLabel getMarginHeightWithTitle:serviceModel.content withFontSize:13];
            XLog(@"cellHeight:%f",cellHeight);
            return cellHeight +140-20;
//            return 200;
        }else {
            return 40;
        }
    }else {
        if (indexPath.row == 0) {
            return 50;
        }else {
            return 144;
            
        }
    }

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 7&&indexPath.row != 0) {
        ServiceContentTabVC *homeServiceVC = [[ServiceContentTabVC alloc]init];
        homeServiceVC.model =self.serviceRecommandArray[indexPath.row-1];
        [self.navigationController pushViewController:homeServiceVC animated:YES];
    }
}
#pragma mark-代理:收藏店铺,进入店铺
- (void)shopCell:(ShopCell *)shopCell withBtn:(UIButton *)btn withSubModel:(nonnull ShopSubModel *)shopSubModell
{
    if (btn.tag == 0) {
        self.urlString = [NSString stringWithFormat:@"%@/collection/insertCollection",kUrl];
        NSString *ids = [NSString stringWithFormat:@"%ld",shopSubModell.id];
        self.dict = @{
                      @"uid":[UserDefaultsHelper readUid],
                      @"id":ids,
                      @"type":@"3",
                      @"token":[UserDefaultsHelper readToken],
                      @"status":[NumberSwitchString numberSwitchString:btn.selected]
                      };
        XLog(@"[NumberSwitchString numberSwitchString:btn.selected]:%@",[NumberSwitchString numberSwitchString:btn.selected]);
        XLog(@"dict:%@",self.dict);
        [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            XLog(@"responseObject:%@",responseObject);
            NSString *message = [responseObject objectForKey:@"message"];
            [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
            if ([message containsString:@"收藏成功"]) {
                shopSubModell.collectStatus = 1;
            }else {
                shopSubModell.collectStatus = 0;
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        }];
    }else {
        MyCollectShopContentVC *vc = [[MyCollectShopContentVC alloc]init];
        vc.model = shopSubModell;
        vc.title = shopSubModell.title;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 1)];
    headerView.backgroundColor = [UIColor whiteColor];
    CGFloat w=kUIScreen.size.width/3;
    if (section == 1) {
        for (int i = 0; i < 3; i++) {
            UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(w*i, 0, w, 40)];
            [headerView addSubview:btn];
            btn.tag = i+1;
            [btn addTarget: self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
            NSArray *titles = @[@"详情介绍",@"客户评价",@"推荐"];
            [btn setTitle:titles[i] forState:UIControlStateNormal];
            if (i == 0) {
                [btn setTitleColor:kOrangeBg forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:16];
            }else {
                [btn setTitleColor:kLabel153Color forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:14];
            }
        }
    }
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return 40;
    }else if (section == 5 ||section == 6 ||section == 7) {
        return 30;
    }else {
        return 0.1;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 0,1)];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 7) {
        return 70;
    }else {
        return 0.1;
    }
}
#pragma mark-代理:点击加载更多
- (void)evaluationMoreCell:(id)evaluationMoreCell withMoreLoadBtn:(UIButton *)moreLaodBtn
{
    CustomeEvaluate *vc = [[CustomeEvaluate alloc]init];
    vc.model = self.model;
    vc.title = @"服务评价";
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark-代理:打电话
-(void)callBtn
{
    if ([[UserDefaultsHelper readAutoLogIn] isEqualToString:@"NO"]) {
        [LogOutAccount presentOutAccount];
        [UIAlertViewWarningAccount showWarningAccount];
    }else if ([UserDefaultsHelper readAutoLogIn].length == 0) {
        [LogOutAccount presentOutAccount];
    }else {
        self.dict = @{
                      @"userId":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken],
                      };
        [CustomeManager POSTCheckTokenWithURLIndex:6 parameters:self.dict success:^(NSDictionary *dict) {
            
        } failure:^(NSError *error) {
            
        }];
    }
}
-(void)checkTokenServiceContentCallPhone:(NSNotification *)info
{
    [self choiceContactWay];
}
-(void)choiceContactWay
{
    YXAlertController *alertController = [YXAlertController alertControllerWithTitle:@"请选择联系方式" message:@"" style:YXAlertControllerStyleActionSheet];
    NSString *way = @"";
    if (self.model.phone.length > 0) {
        way = [NSString stringWithFormat:@"手机号: %@",self.model.phone];
         YXAlertAction *phone = [YXAlertAction actionWithTitle:way style:0 handler:^(YXAlertAction * _Nonnull action) {
            NSMutableString * callPhone= [[NSMutableString alloc] initWithFormat:@"tel:%@",self.model.phone];
            if (@available(iOS 10.0, *)) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
            } else {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
            }
            
            self.urlString = [NSString stringWithFormat:@"%@/relation/insertRelation",kUrl];
            NSString *ids = [NSString stringWithFormat:@"%ld",self.model.id];
            self.dict = @{
                          @"uid":[UserDefaultsHelper readUid],
                          @"relationId":ids,
                          @"type":@"2",
                          @"token":[UserDefaultsHelper readToken]
                          };
            XLog(@"self.dict:%@",self.dict);
            [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                XLog(@"responseObject:%@",responseObject);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                XLog(@"error:%@",error);
            }];
        }];
        [alertController addAction:phone];
    }
    if (self.model.wechat.length > 0) {
        way = [NSString stringWithFormat:@"微信号: %@",self.model.wechat];
        YXAlertAction *wecht = [YXAlertAction actionWithTitle:way style:0 handler:^(YXAlertAction * _Nonnull action) {
            UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
            pasteboard.string = self.model.wechat;
            NSURL *url = [NSURL URLWithString:@"weixin://"];
            BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
            if (canOpen) {
                [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"微信号已复制到剪切板"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [[UIApplication sharedApplication] openURL:url];                    
                });
            }else{
                //        NSLog(@"未安装微信");
                [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"未安装微信"];
            }
        }];
        [alertController addAction:wecht];
    }
    if (self.model.qq.length>0) {
        way = [NSString stringWithFormat:@"QQ号: %@",self.model.qq];
         YXAlertAction *qq = [YXAlertAction actionWithTitle:way style:0 handler:^(YXAlertAction * _Nonnull action) {
            if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
                UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
                NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",self.model.qq]];
                NSURLRequest *request = [NSURLRequest requestWithURL:url];
                [webView loadRequest:request];
                [self.view addSubview:webView];
            }else{
                XLog(@"对不起，您还未安装QQ");
                [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"未安装QQ"];
            }
        }];
        [alertController addAction:qq];
    }
    YXAlertAction *cancel = [YXAlertAction actionWithTitle:@"取消" style:1 handler:^(YXAlertAction * _Nonnull action) {
    }];
    [alertController layoutSettings];
    [alertController addAction:cancel];
    [alertController presentFromViewController:self animated:YES completion:nil];
}
-(void)checkTokenError:(NSNotification *)info
{
//    [LogOutAccount presentOutAccount];
//    [UIAlertViewWarningAccount showWarningAccount];
}
#pragma mark-代理:更新点赞
- (void)serviceEvaluationCell:(ServiceEvaluationCell *)serviceEvaluationCell withGiveLikeBtn:(UIButton *)giveLikeBtn withIndexPath:(NSIndexPath *)indexPath withShopEvaluationEvaluateInfosModel:(ShopEvaluationEvaluateInfosModel *)shopEvaluationEvaluateInfosModel
{
    XLog(@"indexPath.row:%ld",indexPath.row);
    giveLikeBtn.selected = !giveLikeBtn.selected;
    NSString *ids = [NSString stringWithFormat:@"%ld",shopEvaluationEvaluateInfosModel.id];
    NSDictionary *dict = @{
                           @"uid":[UserDefaultsHelper readUid],
                           @"id":ids
                           };
    XLog(@"dict:%@",dict);
    self.urlString = [NSString stringWithFormat:@"%@/associationEvaluate/updateSupportCount",kUrl];
    [self.manager POST:self.urlString parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        XLog(@"responseObject:%@",responseObject);
        NSString *message = [responseObject objectForKey:@"message"];
        [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    ShopEvaluationEvaluateInfosModel *mode = self.shopEvaluationEvaluateInfosMuta[indexPath.row-2];
    if (giveLikeBtn.selected) {
        mode.supportcount++;
    }else {
        mode.supportcount--;
    }
    mode.isSupport = giveLikeBtn.selected;
//    [self.tableView reloadData];
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
#pragma mark-代理:评价投诉
- (void)serviceEvaluationCell:(ServiceEvaluationCell *)serviceEvaluationCell withShopEvaluationEvaluateInfosModel:(ShopEvaluationEvaluateInfosModel *)shopEvaluationEvaluateInfosModel withComplaintBtn:(UIButton *)complaintBtn
{
    self.urlString = [NSString stringWithFormat:@"%@/associationevaluatecomplains/select",kUrl];
    self.dict = @{
                  @"uid":[UserDefaultsHelper readUid],
                  @"token":[UserDefaultsHelper readToken],
                  @"aeid":[NumberSwitchString numberSwitchString:shopEvaluationEvaluateInfosModel.id]
                  };
    XLog(@"self.dict:%@",self.dict);
    [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        XLog(@"responseObject:%@",responseObject);
        NSInteger status = [[responseObject objectForKey:@"status"] integerValue];
        NSString *date = [responseObject objectForKey:@"date"];
        NSString *message = @"";
        if ([date integerValue] == 0) {
            message = @"投诉";
        }else {
            message = @"已投诉";
        }
        self.complationIndex = 1;
        self.complainModel = shopEvaluationEvaluateInfosModel;
        ArrowheadMenu *vc = [[ArrowheadMenu alloc] initDefaultArrowheadMenuWithTitle:@[message] icon:@[@"tousu"] menuPlacements:ShowAtBottom ];
        vc.delegate = self;
        [vc presentMenuView:complaintBtn];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}
#pragma mark-代理:查看评论图片
-(void)serviceEvaluationCell:(ServiceEvaluationCell *)serviceEvaluationCell withLookImage:(NSArray *)images
{
    XLog(@"images:%@",images);
    YHPhotoBrowser *photoView=[[YHPhotoBrowser alloc]init];
    photoView.urlImgArr=images;           //网络链接图片的数组
    photoView.indexTag=0;                      //初始化进去显示的图片下标
    [photoView show];
}
@end
